package com.java.controller;

import com.java.entity.House;
import com.java.service.HouseService;
import com.java.service.impl.HouseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/api/selectHouse")
public class HouseController {
    @Autowired
    HouseService houseService;


   @GetMapping("/findHouseById")
    public Map<String,Object> findHouseById(String houseId){
        Map<String,Object> map=new HashMap<>();
        House house = houseService.findHouseById(houseId);
        if (house!=null){
            map.put("statueCode",200);
            map.put("statueMessage","为你展示详细信息");
            map.put("data",house);
            return map;
        }else {
            map.put("statueCode",0);
            map.put("statueMessage","获取详细信息失败，请重试");
            map.put("data","");
            return map;
        }

   }

    @PutMapping("/findHouse")
    public Map<String,Object> findHouse( @PathParam("city") String city,@PathParam("estate") String estate){
        Map<String,Object>map=new HashMap<>();
        List<House> houseList=new ArrayList<>();
         houseList = houseService.findHouse(city,estate);
         if (houseList.size() >0){
             map.put("statueCode",200);
             map.put("statueMessage","搜索成功");
             map.put("data",houseList);
             return map;
         }else {
             map.put("statueCode",0);
             map.put("statueMessage","未搜到符合条件的房子");
             map.put("data","");
             return map;
         }
    }
}
